﻿CREATE VIEW dbo.v_ExportFromMegasys
AS
SELECT     Q_ccccAcct.XFA_CLASSACCOUNT_F AS XFA_CLASSACCOUNT, Q_ccccAcct.XFA_CLASSACCOUNT AS XFA_CLASSACCOUNT_RAW, Q_ccccAcct.XFA_VIN, 
                      dbo.VinCheck(Q_ccccAcct.XFA_VIN) + 0 AS VC, Q_ccccAcct.XFA_NAME, CONVERT(varchar, Q_ccccAcct.XFA_OPENDT, 111) AS XFA_OPENDT, 
                      Q_ccccAcct.XFA_OPENDT AS XFA_OPENDT_RAW, dbo.MaxDate(Q_ccccAcct.XENTER_DATE, Q_ccccAcct.XFA_OPENDT) AS LastDate, 
                      Q_ccccAcct.XFA_ASTATUS, ISNULL(dbo.t_Dealer.Name, Q_ccccAcct.XFA_DLRNO) AS Dealer, MQ_Account_Tracker.Comment, 
                      MQ_Account_Tracker.Tracker_1 AS [Tracker(6)], MQ_Account_Tracker.Tracker_2 AS TrackerID, CASE WHEN dbo.t_Loan.ID > 0 THEN CONVERT(varchar, 
                      dbo.t_Loan.ID) ELSE '<SPAN style="COLOR:navy;" onclick="ExportFromMegasys(this)">Export</SPAN>' END AS LoanID, dbo.t_Dealer_MsID.DealerID, 
                      dbo.t_Dealer_SalesPersons.ID AS DealerSalesPersonID, Q_ccccAcct.XFA_YEAR, Q_ccccAcct.XFA_MAKE, Q_ccccAcct.XFA_MODEL, 
                      Q_ccccAcct.XSOC_SEC, Q_ccccAcct.XFA_HOMEP, Q_ccccAcct.XFA_WORKP, Q_ccccAcct.XFA_BDATE, Q_ccccAcct.XFA_HOUSENO, 
                      Q_ccccAcct.XFA_STNAME, Q_ccccAcct.XFA_CITY, Q_ccccAcct.XSTATE_CODE, Q_ccccAcct.XZIP_CD, Q_ccccAcct.XFA_MILEAGE, Q_ccccAcct.XFA_COLOR,
                       Q_ccccAcct.XFA_CLASS, Q_ccccAcct.XFA_ACCOUNT
FROM         dbo.t_Loan RIGHT OUTER JOIN
                      dbo.t_Dealer_SalesPersons RIGHT OUTER JOIN
                      dbo.t_Dealer INNER JOIN
                      dbo.t_Dealer_MsID ON dbo.t_Dealer.ID = dbo.t_Dealer_MsID.DealerID AND dbo.t_Dealer.ID = dbo.t_Dealer_MsID.DealerID ON 
                      dbo.t_Dealer_SalesPersons.DealerID = dbo.t_Dealer.ID RIGHT OUTER JOIN
                      megasys.FA_ccccACCT AS Q_ccccAcct ON dbo.t_Dealer_MsID.MsID = Q_ccccAcct.XFA_DLRNO ON 
                      dbo.t_Loan.MsID = Q_ccccAcct.XFA_CLASSACCOUNT_F LEFT OUTER JOIN
                      megasys.MQ_Account_Tracker AS MQ_Account_Tracker ON Q_ccccAcct.XFA_CLASSACCOUNT = MQ_Account_Tracker.XFA_CLASSACCOUNT


GO
EXECUTE sp_addextendedproperty @name = N'MS_DiagramPane1', @value = N'[0E232FF0-B466-11cf-A24F-00AA00A3EFFF, 1.00]
Begin DesignProperties = 
   Begin PaneConfigurations = 
      Begin PaneConfiguration = 0
         NumPanes = 4
         Configuration = "(H (1[36] 4[48] 2[6] 3) )"
      End
      Begin PaneConfiguration = 1
         NumPanes = 3
         Configuration = "(H (1 [50] 4 [25] 3))"
      End
      Begin PaneConfiguration = 2
         NumPanes = 3
         Configuration = "(H (1[50] 2[25] 3) )"
      End
      Begin PaneConfiguration = 3
         NumPanes = 3
         Configuration = "(H (4[30] 2[40] 3) )"
      End
      Begin PaneConfiguration = 4
         NumPanes = 2
         Configuration = "(H (1 [56] 3))"
      End
      Begin PaneConfiguration = 5
         NumPanes = 2
         Configuration = "(H (2[66] 3) )"
      End
      Begin PaneConfiguration = 6
         NumPanes = 2
         Configuration = "(H (4 [50] 3))"
      End
      Begin PaneConfiguration = 7
         NumPanes = 1
         Configuration = "(V (3))"
      End
      Begin PaneConfiguration = 8
         NumPanes = 3
         Configuration = "(H (1[56] 4[18] 2) )"
      End
      Begin PaneConfiguration = 9
         NumPanes = 2
         Configuration = "(H (1 [75] 4))"
      End
      Begin PaneConfiguration = 10
         NumPanes = 2
         Configuration = "(H (1[66] 2) )"
      End
      Begin PaneConfiguration = 11
         NumPanes = 2
         Configuration = "(H (4 [60] 2))"
      End
      Begin PaneConfiguration = 12
         NumPanes = 1
         Configuration = "(H (1) )"
      End
      Begin PaneConfiguration = 13
         NumPanes = 1
         Configuration = "(V (4))"
      End
      Begin PaneConfiguration = 14
         NumPanes = 1
         Configuration = "(V (2) )"
      End
      ActivePaneConfig = 2
   End
   Begin DiagramPane = 
      Begin Origin = 
         Top = 0
         Left = 0
      End
      Begin Tables = 
         Begin Table = "t_Loan"
            Begin Extent = 
               Top = 211
               Left = 274
               Bottom = 400
               Right = 454
            End
            DisplayFlags = 280
            TopColumn = 0
         End
         Begin Table = "t_Dealer_SalesPersons"
            Begin Extent = 
               Top = 382
               Left = 824
               Bottom = 538
               Right = 975
            End
            DisplayFlags = 280
            TopColumn = 0
         End
         Begin Table = "t_Dealer"
            Begin Extent = 
               Top = 290
               Left = 600
               Bottom = 399
               Right = 751
            End
            DisplayFlags = 280
            TopColumn = 0
         End
         Begin Table = "t_Dealer_MsID"
            Begin Extent = 
               Top = 140
               Left = 455
               Bottom = 219
               Right = 606
            End
            DisplayFlags = 280
            TopColumn = 0
         End
         Begin Table = "MQ_Account_Tracker"
            Begin Extent = 
               Top = 6
               Left = 261
               Bottom = 141
               Right = 446
            End
            DisplayFlags = 280
            TopColumn = 0
         End
         Begin Table = "Q_ccccAcct"
            Begin Extent = 
               Top = 6
               Left = 38
               Bottom = 526
               Right = 223
            End
            DisplayFlags = 280
            TopColumn = 0
         End
      End
   End
   Begin SQLPane = 
   End
   Begin DataPane = 
      Begin ParameterDefaults = ""
      End
      Begin ColumnWidths = 29
         Width = 284
         Width =', @level0type = N'SCHEMA', @level0name = N'dbo', @level1type = N'VIEW', @level1name = N'v_ExportFromMegasys';


GO
EXECUTE sp_addextendedproperty @name = N'MS_DiagramPane2', @value = N'1500
         Width = 1500
         Width = 1500
         Width = 1500
         Width = 1500
         Width = 1500
         Width = 2850
         Width = 1500
         Width = 1500
         Width = 1500
         Width = 1500
         Width = 1500
         Width = 3510
         Width = 1500
         Width = 1500
         Width = 1500
         Width = 1500
         Width = 1500
         Width = 1500
         Width = 1500
         Width = 1500
         Width = 1500
         Width = 1500
         Width = 1500
         Width = 1500
         Width = 1500
         Width = 1500
         Width = 1500
      End
   End
   Begin CriteriaPane = 
      PaneHidden = 
      Begin ColumnWidths = 11
         Column = 11925
         Alias = 2490
         Table = 1170
         Output = 720
         Append = 1400
         NewValue = 1170
         SortType = 1350
         SortOrder = 1410
         GroupBy = 1350
         Filter = 1350
         Or = 1350
         Or = 1350
         Or = 1350
      End
   End
End', @level0type = N'SCHEMA', @level0name = N'dbo', @level1type = N'VIEW', @level1name = N'v_ExportFromMegasys';


GO
EXECUTE sp_addextendedproperty @name = N'MS_DiagramPaneCount', @value = 2, @level0type = N'SCHEMA', @level0name = N'dbo', @level1type = N'VIEW', @level1name = N'v_ExportFromMegasys';

